<template>
    <div class="reader_view">
        <web-view :webview-styles="webviewStyles" :src="url"></web-view>
    </div>
</template>

<script>
import {
    home
} from '../../services/index.js';
import {
    mapState,
} from "vuex";
export default {
    data() {
        return {
            rawHtml: '',
            ebookId: '',
            currentHref: '',
            url: '',
            chapterUid: '',
        };
    },
    onLoad(params) {
        this.url = params.webviewUrl;
        // this.initData(params);
        // this.url = `http://localhost:8080/?userToken=${this.userToken.token}&ebookId=${params.ebookId}&currentHref=${params.href}&currentIndex=${params.currentIndex}&chapterUid=${params.chapterUid}&clientType=1`
    },
    methods: {
        reciveMessage(msg) {
            console.log(msg);
        },
        async getEbookProgress(params) {
            let res = await home.getEbookProgress({
                ebookId: params.ebookId,
            })
        },
        async initData(params) {
            var css = /[^"]+(\.css)/gi;
            let res = await home.getEbookDownload({
                ebookId: params.ebookId,
                href: params.href,
            });
            // https://www.realbook.com.cn/ebook/33/download?href=index_split_000.html
            var cssLinkAry = res.match(css);
            // let cssStrsArray = await Promise.all(
            //     cssLinkAry.map((url) => this.$api.getCssFile(`getFile/ebook/css/${params.ebookId}/${url}`))
            // )
            // let cssStr = '';
            // cssStrsArray.forEach((str) => {
            //     cssStr += str;
            // })
            // console.log(cssStr);
            // var style = document.createElement('style')
            // style.type = 'text/css'
            // style.appendChild(document.createTextNode(cssStr))
            // var head = document.getElementsByTagName('head')[0]
            // head.appendChild(style)
            this.rawHtml = res;
        },
    },
    computed: {
        ...mapState(["userInfo", "userToken"]),
    },
    mounted() {
    },
};
</script>

<style lang="scss" scoped>
.reader_view::-webkit-scrollbar {
    width: 0rpx;
    height: 0rpx;
    background-color: transparent;
}

.reader_view {
    -webkit-overflow-scrolling: touch;
}
</style>
